package com.freshcity.manager.support
{
	import com.freshcity.utils.StringUtil;
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class FixMsgRollImpl extends Sprite
	{
		private const _width:int=185;
		private const _height:int=120;
		
		private var _msgs:Vector.<String>;
		
		private var txtFormat:TextFormat;
		private var glowFilter:GlowFilter;
		
		public function FixMsgRollImpl()
		{
			_msgs=new Vector.<String>();
			txtFormat=new TextFormat("宋体", 12, 0x94704d);
			txtFormat.leading=4;
			this.addEventListener(Event.ADDED_TO_STAGE, init);
			this.glowFilter = new GlowFilter(0, 1, 2, 2, 2);
			TweenLite.delayedCall(1, onTick);
		}
		
		private function onTick():void
		{
			if (_msgs.length > 0)
			{
				var text:String=this._msgs.shift();
				
				var txt:TextField = new TextField();
				txt.multiline = true;
				txt.defaultTextFormat = txtFormat;
				txt.wordWrap = true;
				
				//txt.filters = [glowFilter];
				txt.width=_width;
				
				txt.htmlText = "".concat(StringUtil.getNow(),"->",text);
				txt.y=_height;
				addChild(txt);
				
				var len:int = this.numChildren;
				var it:TextField;
				
				for (var j:int = 0; j < len; j++) 
				{
					it = this.getChildAt(j) as TextField;	
					TweenLite.to(it, 0.2, {y: "-".concat(txt.textHeight),onComplete:handlerData,onCompleteParams:[it]});
				}
				
			}
			TweenLite.delayedCall(1, onTick);
		}
		
		private function handlerData(it:TextField):void
		{
			if (it.y < 0)
			{
				TweenMax.to(it,0.2,{autoAlpha:0,onComplete:function():void{
					if(it.parent)it.parent.removeChild(it);
				}});
			}
		}
		
		private function init(event:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, init);
			
			x=stage.stageWidth - _width - 4;
			y=stage.stageHeight - _height - 120;
		}
		
		public function showMsg(text:String):void
		{
			this._msgs.push(text);
		}
		
		
	}
}